﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using WpfApp.Tools.Controls;
using WpfApp.View.LineManage;
using WpfApp.View.SystemInformation;

namespace WpfApp
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        #region 全局变量
        public static TabControl TC;
        int intDownTag = 0;//当前选择按钮的tag
        //声明定时器
        private DispatcherTimer showtimer;
        
        #endregion
        public MainWindow(string strStaffName, string strBranch)
        {
            InitializeComponent();
            TbDepartment.Text = strBranch + "：";
            TbEmployee.Text = strStaffName;
            ///显示时间
            showtimer = new DispatcherTimer();//实例化
            showtimer.Tick += new EventHandler(GetTime);
            showtimer.Interval = new TimeSpan(0, 0, 0, 1, 0);//控制时间在一秒钟跳动一次
            showtimer.Start();//开启时间
            //显示图片
            //string strPictureName=

        }
        /// <summary>
        /// 获取时间并把时间赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void GetTime(object sender,EventArgs e)
        {
            txt_Time.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//确定时间格式
        }
        #region 添加选项卡
        public static void AddItem(object sender,string trname,UserControl uc)
        {
            bool bolWhetherBe = false;//定义开关是否存在当前选项
            //判断当前选项卡的个数是否大于0
            if (TC.Items.Count > 0)
            {
                for (int i = 0; i < TC.Items.Count; i++)
                {
                    if (((UCTabItemWithClose)TC.Items[i]).Name == trname) {
                        TC.SelectedItem = (UCTabItemWithClose)TC.Items[i];
                        bolWhetherBe = true;
                        break;
                    }
                }
                //是否存在当前选项
                if (bolWhetherBe == false)
                {
                    UCTabItemWithClose item = new UCTabItemWithClose();//创建子选项
                    item.Name = trname;//名称
                    item.Header = string.Format(trname);//标头名称
                    item.Content = uc;//子选择里面的内容           
                    item.Margin = new Thickness(0, 0, 1, 0);
                    item.Height = 28;
                    TC.Items.Add(item);//添加子选项
                    TC.SelectedItem = item;//选中子选项
                }
            }
            else
            {
                UCTabItemWithClose item = new UCTabItemWithClose();//创建子选项
                item.Name = trname;//名称
                item.Header = string.Format(trname);//标头名称
                item.Content = uc;//子选择里面的内容           
                item.Margin = new Thickness(0, 0, 1, 0);
                item.Height = 28;
                TC.Items.Add(item);//添加子选项
                TC.SelectedItem = item;//选中子选项
            }

        }
        #endregion


        private void wd_Main_Loaded(object sender, RoutedEventArgs e)
        {
            //获取选项卡
            TC = tab_Main;
            //最大化
            btn_Max_Click(null, null);
        }
        Rect rcnormal;//定义一个全局rect记录还原状态下窗口的位置和大小。
        /// <summary>
        /// 最小化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Min_Click(object sender, RoutedEventArgs e)
        {
            wd_Main.WindowState = WindowState.Minimized;
        }
        /// <summary>
        /// 缩小全屏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Normal_Click(object sender, RoutedEventArgs e)
        {
            this.Left = rcnormal.Left;
            this.Top = rcnormal.Top;
            this.Width = rcnormal.Width;
            this.btn_Max.Visibility = Visibility.Visible;
            this.btn_Normal.Visibility = Visibility.Collapsed;
        }
        //最大化
        private void btn_Max_Click(object sender, RoutedEventArgs e)
        {
            this.btn_Max.Visibility = Visibility.Collapsed;
            this.btn_Normal.Visibility = Visibility.Visible;
            rcnormal = new Rect(this.Left, this.Top, this.Width, this.Height);////保存下当前位置与大小
            this.Left = 0;
            this.Top = 0;
            Rect rc = SystemParameters.WorkArea;
            this.Width = rc.Width;
            this.Height = rc.Height;
        }
        /// <summary>
        /// 退出系统
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Exit_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("你确定要退出吗？", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                Application.Current.Shutdown();
            }
        }
        #region 左边一级菜单按妞（控制二级菜单栏的显示）
        private void LeftButtonClick(object sender,RoutedEventArgs e)
        {
            //嵌套菜单
            //判断按钮是不是重复选择           
            if (intDownTag == Convert.ToInt32(((Button)sender).Tag))
            {

                if (((Button)sender) == btnSystemInformation)
                {
                    //控制【系统管理】菜单组件隐藏
                    btnSystemInformationBorder.Visibility = Visibility.Collapsed;
                }
                else if (((Button)sender) == btnTrainOrder)
                {
                    //控制【车次管理】菜单组件隐藏
                    btnTrainOrderBorder.Visibility = Visibility.Collapsed;
                }
                else if (((Button)sender) == btnLineManage)
                {
                    //控制【线路管理】菜单组件隐藏
                    btnLineManageBorder.Visibility = Visibility.Collapsed;
                }
                else if (((Button)sender) == btnTicketTask)
                {
                    //控制【票务管理】菜单组件隐藏
                    btnTicketTaskBorder.Visibility = Visibility.Collapsed;
                }
                else if (((Button)sender) == btnDataStatistics)
                {
                    //控制【数据统计】菜单组件隐藏
                    btnDataStatisticsBorder.Visibility = Visibility.Collapsed;
                }
                //调整左边菜单栏的显示和隐藏
                intDownTag = 0;
                return;
            }
            else if (((Button)sender) == btnSystemInformation)
            {
                //控制【系统管理】菜单组件显示
                btnSystemInformationBorder.Visibility = Visibility.Visible;
                //控制【车次管理】菜单组件隐藏
                btnTrainOrderBorder.Visibility = Visibility.Collapsed;
                //控制【线路管理】菜单组件隐藏
                btnLineManageBorder.Visibility = Visibility.Collapsed;
                //控制【票务管理】菜单组件隐藏
                btnTicketTaskBorder.Visibility = Visibility.Collapsed;
                //控制【数据统计】菜单组件隐藏
                btnDataStatisticsBorder.Visibility = Visibility.Collapsed;
            }

            else if (((Button)sender) == btnTrainOrder)
            {

                //控制【系统管理】菜单组件隐藏
                btnSystemInformationBorder.Visibility = Visibility.Collapsed;
                //控制【车次管理】菜单组件显示
                btnTrainOrderBorder.Visibility = Visibility.Visible;
                //控制【线路管理】菜单组件隐藏
                btnLineManageBorder.Visibility = Visibility.Collapsed;
                //控制【票务管理】菜单组件隐藏
                btnTicketTaskBorder.Visibility = Visibility.Collapsed;
                //控制【数据统计】菜单组件隐藏
                btnDataStatisticsBorder.Visibility = Visibility.Collapsed;
            }
            else if (((Button)sender) == btnLineManage)
            {
                //控制【系统管理】菜单组件隐藏
                btnSystemInformationBorder.Visibility = Visibility.Collapsed;
                //控制【车次管理】菜单组件隐藏
                btnTrainOrderBorder.Visibility = Visibility.Collapsed;
                //控制【线路管理】菜单组件显示
                btnLineManageBorder.Visibility = Visibility.Visible;
                //控制【票务管理】菜单组件隐藏
                btnTicketTaskBorder.Visibility = Visibility.Collapsed;
                //控制【数据统计】菜单组件隐藏
                btnDataStatisticsBorder.Visibility = Visibility.Collapsed;
            }
            else if (((Button)sender) == btnTicketTask)
            {
                //控制【系统管理】菜单组件隐藏
                btnSystemInformationBorder.Visibility = Visibility.Collapsed;
                //控制【车次管理】菜单组件隐藏
                btnTrainOrderBorder.Visibility = Visibility.Collapsed;
                //控制【线路管理】菜单组件隐藏
                btnLineManageBorder.Visibility = Visibility.Collapsed;
                //控制【票务管理】菜单组件显示
                btnTicketTaskBorder.Visibility = Visibility.Visible;
                //控制【数据统计】菜单组件隐藏
                btnDataStatisticsBorder.Visibility = Visibility.Collapsed;
            }
            else if (((Button)sender) == btnDataStatistics)
            {
                //控制【系统管理】菜单组件隐藏
                btnSystemInformationBorder.Visibility = Visibility.Collapsed;
                //控制【车次管理】菜单组件隐藏
                btnTrainOrderBorder.Visibility = Visibility.Collapsed;
                //控制【线路管理】菜单组件隐藏
                btnLineManageBorder.Visibility = Visibility.Collapsed;
                //控制【票务管理】菜单组件隐藏
                btnTicketTaskBorder.Visibility = Visibility.Collapsed;
                //控制【数据统计】菜单组件显示
                btnDataStatisticsBorder.Visibility = Visibility.Visible;
            }
            intDownTag = Convert.ToInt32(((Button)sender).Tag);//当前选择按钮的tag

        }
       
        #endregion
        #region 菜单按妞（点击嵌套页面）
        //按钮（修改密码）
        private void btnUpdatePassword_Click(object sender, RoutedEventArgs e)
        {

        }
        //按钮（员工管理）
        private void btnStaffInformation_Click(object sender, RoutedEventArgs e)
        {
            UC_StaffInformation myStaff = new UC_StaffInformation();
            AddItem(sender, btnStaffInformation.Content.ToString().Trim(), myStaff);
        }
        //按钮（旅客管理）
        private void btnTravellerInformation_Click(object sender, RoutedEventArgs e)
        {
            UC_TravellerInformation myTraveller = new UC_TravellerInformation();
            AddItem(sender, btnTravellerInformation.Content.ToString().Trim(), myTraveller);
        }
        //按钮（员工账户管理）
        private void btnStaffAccountManage_Click(object sender, RoutedEventArgs e)
        {
            UC_StaffAccountManage myUC = new UC_StaffAccountManage();
            AddItem(sender, btnStaffAccountManage.Content.ToString().Trim(), myUC);
        }
        //按钮（权限管理）
        private void btnPowerManage_Click(object sender, RoutedEventArgs e)
        {

        }
        //按钮（系统操作日志）
        private void btnSystemOperateLog_Click(object sender, RoutedEventArgs e)
        {

        }
        //按钮（生成线路）
        private void btnCreateLine_Click(object sender, RoutedEventArgs e)
        {
            UC_CreateLines uC_Create = new UC_CreateLines();
            AddItem(sender, btnCreateLine.Content.ToString().Trim(), uC_Create);
        }
        //按钮（站点管理）
        private void btnStationManage_Click(object sender, RoutedEventArgs e)
        {
            UC_StationManage myStationManage = new UC_StationManage();
            AddItem(sender, btnStationManage.Content.ToString().Trim(), myStationManage);
        }
        //按钮（车辆管理）
        private void btnCompartment_Click(object sender, RoutedEventArgs e)
        {

        }
        //按钮（车次管理）
        private void btnCarOrder_Click(object sender, RoutedEventArgs e)
        {


        }
        //按钮（车票生成）
        private void btnTicket_Click(object sender, RoutedEventArgs e)
        {

        }
        //按钮（车票分配)
        private void btnTicketDetails_Click(object sender, RoutedEventArgs e)
        {

        }
        //按钮（票价规则)
        private void btnTicketPrice_Click(object sender, RoutedEventArgs e)
        {

        }
        //销售金额统计
        private void btnSaleStatistics_Click(object sender, RoutedEventArgs e)
        {

        }
        //按钮（各站旅客流量)
        private void btnSitePeopleStream_Click(object sender, RoutedEventArgs e)
        {

        }
        //按钮（网上账户购票次数)
        private void btnWebShopTicketNumber_Click(object sender, RoutedEventArgs e)
        {

        }
        #endregion
    }
    


}
